package com.test.postgresql;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.test.db.api.UserDao;
import com.test.db.api.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

@Service
@ConditionalOnProperty(name = "common.db", havingValue = "postgresql")
public class PGUserDAO implements UserDao {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getInfo() {
        PGUser user = userMapper.selectOne(
                Wrappers.<PGUser>lambdaQuery().eq(PGUser::getName, "pg"));
        return BeanUtil.toBean(user, User.class);
    }
}
